#!/bin/bash

if [ $# -ne 1 ]; then
    echo "Usage: \$0 <file_path>"
    exit 1
fi

file_path="$1"
dest_path="/home/code/origin"

# 获取文件路径的最后一个目录名作为 project_name
project_name=$(basename "$file_path")
echo $project_name
rm -rf "$dest_path/$project_name"

# 判断 project_name 结尾是否为 "backend"
if [[ "$project_name" == *backend ]]; then
    echo "Executing 'mvn clean' in $file_path"
    cd "$file_path" || exit 1
    mvn clean
    echo "Copying all files to $dest_path/$project_name"
    mkdir -p "$dest_path/$project_name"
    cp -r ./. "$dest_path/$project_name"
elif [[ "$project_name" == *frontend ]]; then
    echo "Copying non .git, node_modules files from $file_path to $dest_path/$project_name"
    cd "$file_path" || exit 1
    mkdir -p "$dest_path/$project_name"
    rm -rf .git
	rm -rf node_modules
	cp -r ./. "$dest_path/$project_name"
else
    echo "Executing 'mvn clean' in $file_path"
    cd "$file_path" || exit 1
    mvn clean
    echo "Copying all files to $dest_path/$project_name"
    mkdir -p "$dest_path/$project_name"
    cp -r ./. "$dest_path/$project_name"
fi

echo "Operation completed successfully."